// pages/mechanismdetails/mechanismdetails.js
import { ajax, src, util } from "../../utils/util.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // imgUrls: [
    //   'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
    //   'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
    //   'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'
    // ],
    // indicatorDots: false,
    // autoplay: false,
    // interval: 5000,
    // duration: 1000,
    // current:'',
    uqid:'',
    mdetails:[]
  },
  //轮播图滑动获取下标
  bindChange(e) {
    console.log(e.detail.current)
    this.setData({
      current: e.detail.current
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var uqid = wx.getStorageSync("uqid");
    var id = options.id;
    this.setData({
      uqid: uqid,
      id:id
    });
    this.mechDetails();
  },

  mechDetails:function(){
    ajax("/api/index/mechanism_show", {
      data: {
        uqid: this.data.uqid,
        id: this.data.id,
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
      method: 'GET'
    }, res => {
      console.log(res);
      if (res.error == 0) {
        this.setData({
          mdetails: res.data
        });
        // console.log(mdetails)
      }
    })
  },

  phoneCall: function (e) {
    var phone = e.currentTarget.dataset.phone;
    if (phone != undefined || phone != ''){
      wx.makePhoneCall({
        phoneNumber: phone,
        success: function () {
        },
      })
    }
  },

  tomap:function(){
    // console.log(this.data.mdetails.longitude)
    // wx.navigateTo({
    //   url: '/pages/map/map?longitude=' + this.data.mdetails.longitude + "&latitude=" + this.data.mdetails.latitude,
    // })
    var latitude = Number(this.data.mdetails.latitude)
    var longitude = Number(this.data.mdetails.longitude)
    var name = this.data.mdetails.name
    var address = this.data.mdetails.address
    wx.openLocation({
      latitude,
      longitude,
      scale: 18,
      name,
      address
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})